﻿using System.Collections.Generic;
using TS3QueryLib.Core.CommandHandling;
using TS3QueryLib.Core.Common.Responses;
using TS3QueryLib.Core.Server.Entities;
using System.Linq;

namespace TS3QueryLib.Core.Server.Responses
{
    public class LogViewResponse : ResponseBase<LogViewResponse>
    {
        #region Properties

        public List<LogEntry> LogEntries { get; protected set; }
        public int FileSize { get; protected set; }
        public uint LogPositionToContinueReading { get; protected set; }

        #endregion

        #region Non Public Methods

        protected override void FillFrom(string responseText, params object[] additionalStates)
        {
            CommandParameterGroupList list = CommandParameterGroupList.Parse(BodyText);

            if (list.Count == 0)
                return;

            FileSize = list.GetParameterValue<int>("file_size");
            LogPositionToContinueReading = list.GetParameterValue<uint>("last_pos");
            LogEntries = new List<LogEntry>(list.Select(e => LogEntry.Parse(e, list[0])));
        }

        #endregion
    }
}
